﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace MedicinaMuncii.UI.Mvc.Util.ExtensionMethods
{
    public static class StringExtenstions
    {
        public static string DefaultIfNull(this string source, string defaultValue = "")
        {
            if (source == null)
            {
                source = defaultValue;
            }

            return source;
        }

        public static string ToStringEnumeration(this IEnumerable<string> source, string defaultValue = "")
        {
            if (source == null)
            {
                return string.Empty;
            }

            StringBuilder result = new StringBuilder();
            bool firstItem = true;

            foreach (string item in source)
            {
                if (firstItem)
                {
                    firstItem = false;
                }
                else
                {
                    result.Append(", ");
                }

                result.Append(item);
            }

            return result.ToString();
        }
    }
}